package com.inspur.xiaoju.security;

import com.inspur.xiaoju.model.SurveyResponse;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class PluginManager {
    private final List<SecurityPlugin> plugins = new ArrayList<>();
    
    public void registerPlugin(SecurityPlugin... plugins) {
        for (SecurityPlugin plugin : plugins) {
            this.plugins.add(plugin);
        }
    }
    
    public void encryptResponseData(SurveyResponse responseData) {
        for (SecurityPlugin plugin : plugins) {
            plugin.encryptResponseData(responseData);
        }
    }
    
    public void decryptResponseData(SurveyResponse responseData) {
        for (SecurityPlugin plugin : plugins) {
            plugin.decryptResponseData(responseData);
        }
    }
    
    public void maskData(Map<String, Object> data) {
        for (SecurityPlugin plugin : plugins) {
            plugin.maskData(data);
        }
    }
    
    public String genSurveyPath() {
        for (SecurityPlugin plugin : plugins) {
            String path = plugin.genSurveyPath();
            if (path != null) {
                return path;
            }
        }
        return null;
    }
}